#!/usr/bin/perl -w

#=======
#cron:
#10 23 * * * /home/jctong/scripts/drive_status/insert_drive_status.pl

use strict;
use DBI;

system('scp root@netbackup:/export/home/root/cron/output/query_drive_status.output .');

open(INPUT,"query_drive_status.output") || die "no input file";


        my $db="jctong";
        my $table="drive_status";
        my $host="ilwrath";
        my $user="nbuadmin";
        my $password="asdfjk";

       my $dbh = DBI->connect ("DBI:mysql:database=$db:host=$host",$user,$password) or die "Can't connect to database: $DBI::errstr
\n";
       my $sth=$dbh->prepare('insert into drive_status (drive_index,status,timestamp) values (?,?,?)');




while(defined(my $line=<INPUT>)){
	my($drive_index,$status,$timestamp)=split(/\^/,$line);
	$sth->execute($drive_index,$status,$timestamp);
}	
